package com.qipay.mapper;

import com.qipay.baas.model.ChannelType;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.math.BigDecimal;
import java.util.List;

public interface ChannelTypeMapper extends com.qipay.baas.mapper.ChannelTypeMapper{

    @Delete({
        "delete from channel_type",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into channel_type (`name`, cp_fee_recharge, ",
        "agent_fee_recharge)",
        "values (#{name,jdbcType=VARCHAR}, #{cpFeeRecharge,jdbcType=DECIMAL}, ",
        "#{agentFeeRecharge,jdbcType=DECIMAL})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(ChannelType record);


    @Select({
        "select",
        "id, `name`, cp_fee_recharge, agent_fee_recharge,rate_advance,`status`",
        "from channel_type"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="cp_fee_recharge", property="cpFeeRecharge", jdbcType=JdbcType.DECIMAL),
        @Result(column="agent_fee_recharge", property="agentFeeRecharge", jdbcType=JdbcType.DECIMAL),
        @Result(column="rate_advance", property="rateAdvance", jdbcType=JdbcType.DECIMAL),
        @Result(column="status", property="status", jdbcType=JdbcType.TINYINT)
    })
    List<ChannelType> selectAll();


    @Select({
            "select",
            "id, `name`, cp_fee_recharge, agent_fee_recharge ,status,rate_advance",
            "from channel_type where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="cp_fee_recharge", property="cpFeeRecharge", jdbcType=JdbcType.DECIMAL),
            @Result(column="agent_fee_recharge", property="agentFeeRecharge", jdbcType=JdbcType.DECIMAL),
            @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
            @Result(column="rate_advance", property="rateAdvance", jdbcType=JdbcType.DECIMAL)
    })
    List<ChannelType> findById(@Param("id") long id);

    @Update({
        "update channel_type",
        "set cp_fee_recharge = #{cpFeeRecharge,jdbcType=DECIMAL},",
        "agent_fee_recharge = #{agentFeeRecharge,jdbcType=DECIMAL},",
        "rate_advance = #{rateAdvance,jdbcType=DECIMAL}",
         "where id = #{id,jdbcType=BIGINT}"
    })
    int update(@Param("id") long id, @Param("cpFeeRecharge") BigDecimal cpFeeRecharge, @Param("agentFeeRecharge") BigDecimal agentFeeRecharge,@Param("rateAdvance") BigDecimal rateAdvance);

    @Update({
            "update channel_type",
            "set status = #{status,jdbcType=TINYINT}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateStatus(@Param("id") long id, @Param("status") Byte status);


    /*
   根据id修改cpFeeRecharge
    */
    @Update({
            "update channel_type",
            "set cp_fee_recharge = #{cpFeeRecharge,jdbcType=DECIMAL} ",
            "where id = #{id,jdbcType=BIGINT}"
    })
    //根据ID修改数据库channel_type表中的ID、cp_fee_recharge、agent_fee_recharge、rate_advance等字段的数据
    int updateCpFeeRechargeByid(@Param("id") long id, @Param("cpFeeRecharge") BigDecimal cpFeeRecharge);

    /*
   根据id修改agentFeeRecharge
    */
    @Update({
            "update channel_type",
            "set agent_fee_recharge = #{agentFeeRecharge,jdbcType=DECIMAL} ",
            "where id = #{id,jdbcType=BIGINT}"
    })
    //根据ID修改数据库channel_type表中的IDagent_fee_recharge等字段的数据
    int updateAgentFeeRechargeByid(@Param("id") long id, @Param("agentFeeRecharge") BigDecimal agentFeeRecharge);


    /*
  根据id修改rateAdvance
   */
    @Update({
            "update channel_type",
            "set rate_advance = #{rateAdvance,jdbcType=DECIMAL} ",
            "where id = #{id,jdbcType=BIGINT}"
    })
    //根据ID修改数据库channel_type表中的ID、rate_advance等字段的数据
    int updateRateAdvanceByid(@Param("id") long id, @Param("rateAdvance") BigDecimal rateAdvance);

}